﻿using System;

namespace OpenLightGroup.Common
{

    /// <summary>
    /// Class that holds the static extension methods for EventHandlers
    /// </summary>
    public static class DateTimeExtensions
    {
        /// <summary>
        /// How much time has passed from the date until now or how long until the date.
        /// </summary>
        /// <param name="date">Date to calculate</param>
        /// <returns>
        /// A TimeSpan of how much time has passed from the date until now or how long until the date.
        /// </returns>
        public static TimeSpan TimeSpanToNow(this DateTime date)
        {            
            return DateTime.Now - date;
        }

        /// <summary>
        /// Calculates age from startDate to now.
        /// </summary>
        /// <param name="startDate">The start date. This could be the date of birth for example.</param>
        /// <returns></returns>
        public static Age ToAge(this DateTime startDate)
        {
            DateTime endDate = DateTime.Now;

            return Age.FromDates(startDate, endDate);

        }

        /// <summary>
        /// Calculates age from startDate to endDate.
        /// </summary>
        /// <param name="startDate">The start date. This could be the date of birth for example.</param>
        /// <param name="endDate">The end date. The later date to use in the calculation of age.</param>
        /// <returns></returns>
        public static Age ToAge(this DateTime startDate, DateTime endDate)
        {

            return Age.FromDates(startDate, endDate);

        }
    }
}
